package com.itheima.reggie.service.impl;

import com.itheima.reggie.entity.User;
import com.itheima.reggie.mapper.UserMapper;
import com.itheima.reggie.service.UserService;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private UserMapper userMapper;
    @Override
    public User login(String phone, String code, String codeInSession) {
        User dbuser = null;
        if (codeInSession != null && code.equalsIgnoreCase(codeInSession)){
            dbuser = userMapper.findByPhone(phone);
            if (dbuser==null){
                dbuser = new User();
                dbuser.setPhone(phone);
                dbuser.setStatus(1);
                userMapper.save(dbuser);
            }
        }
        return dbuser;
    }
}
